package com.atguigu.meinian.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.meinian.mapper.AddressMapper;
import com.atguigu.meinian.pojo.Address;
import com.atguigu.meinian.service.AddressService;
import com.atguigu.meinian.vo.PageResult;
import com.atguigu.meinian.vo.QueryPageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zbystart
 * @create 2021-06-29 18:11
 */
@Service(interfaceClass = AddressService.class)
@Transactional
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public List<Address> findAllMaps() {

        return addressMapper.selectAllMaps();
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());

        Page<Address> page = addressMapper.selectAddressByQuery(queryPageBean.getQueryString());

        return new PageResult(page.getTotal(),page.getResult(),page.getPageNum());
    }

    @Override
    public void addAddress(Address address) {

        addressMapper.insertAddress(address);
    }

    @Override
    public void deleteAddressById(Integer id) {
        addressMapper.deleteAddressById(id);
    }
}
